package org.serverct.finalfight.internal.info;

import org.bukkit.Bukkit;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.entity.Player;
import org.serverct.finalfight.internal.game.basic.BasicGame;
import org.serverct.finalfight.internal.game.basic.BasicGamer;
import org.serverct.finalfight.util.CustomSettings;
import org.serverct.finalfight.util.StringPair;

import java.util.HashSet;
import java.util.UUID;

public class BossBarHandler {
    public static HashSet<BossBar> bars = new HashSet<>();

    public static BossBar sendBar(Player player, String langPath, BarColor color, StringPair... replacers) {
        BossBar bar = Bukkit.createBossBar(CustomSettings.getLanguageWithoutPrefix(langPath, replacers), color, BarStyle.SOLID);
        bar.addPlayer(player);
        return bar;
    }

    public static void removeAll() {
        for (BossBar bar : bars) {
            bar.removeAll();
        }
    }

    public static void removeBar(BossBar bar) {
        bar.removeAll();
    }

    public static BossBar broadcastBar(BasicGame game, boolean ignoreDead, String langPath, BarColor color, StringPair... replacers) {
        BossBar bar = Bukkit.createBossBar(CustomSettings.getLanguageWithoutPrefix(langPath, replacers), color, BarStyle.SOLID);
        for (UUID uuid : game.players.keySet()) {
            Player player = Bukkit.getPlayer(uuid);
            BasicGamer stat = game.players.get(uuid);
            if ((!stat.isAlive) && ignoreDead) {
                continue;
            }
            bar.addPlayer(player);
        }
        return bar;
    }
}
